import 'dart:convert';

import 'rule/rule.dart';
import 'rule/rule_factory.dart';

class ExploreRule {
  Rule? bookList;
  Rule? name;
  Rule? author;
  Rule? intro;
  Rule? kind;
  Rule? lastChapter;
  Rule? updateTime;
  Rule? bookUrl;
  Rule? coverUrl;
  Rule? wordCount;


  ExploreRule(this.bookList, this.name, this.author, this.intro, this.kind, this.lastChapter, this.updateTime,
      this.bookUrl, this.coverUrl, this.wordCount);

  ExploreRule.fromJson(dynamic json) {
    json = checkJson(json);
    bookList = json['bookList'];
    name = json['name'];
    author = json['author'];
    intro = json['intro'];
    kind = json['kind'];
    lastChapter = json['lastChapter'];
    updateTime = json['updateTime'];
    bookUrl = json['bookUrl'];
    coverUrl = json['coverUrl'];
    wordCount = json['wordCount'];
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map['bookList'] = bookList;
    map['name'] = name;
    map['author'] = author;
    map['intro'] = intro;
    map['kind'] = kind;
    map['lastChapter'] = lastChapter;
    map['updateTime'] = updateTime;
    map['bookUrl'] = bookUrl;
    map['coverUrl'] = coverUrl;
    map['wordCount'] = wordCount;
    return map;
  }

  Map<String,dynamic> checkJson(dynamic jsonString){
    if (jsonString == null) {
      jsonString =Map();
    }else if(jsonString is String){
      try{
        jsonString = json.decode(jsonString);
        if(!(jsonString is Map<String,dynamic>)){
          jsonString =Map();
        }
      }catch (e){
        jsonString =Map();
      }
    }else if(jsonString is ExploreRule){
      jsonString = jsonString.toJson();
    }else if(!(jsonString is Map<String,dynamic>)){
      jsonString =Map();
    }
    return jsonString;
  }

}
